﻿using System;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using DevExpress.Web.ASPxTabControl;
using olierFrm.WebFormDev;
using olierFrm.DataBase.FrameWork.StdQuery;
using olierFrm.WebFormDev.StdQuery;

namespace WebFormDev.StdQueryPack
{
    public partial class IFrameStdQueryContent : System.Web.UI.Page
    {
        protected void Page_PreInit(object sender, EventArgs e)
        {
            ManageSystem.IsLogin();
            ManageSystem.SetTheme(Page);
            //没有QueryName只显示菜单，为了重复利用该页面（系统首页和StdQuery）

        }

        protected void Page_Load(object sender, EventArgs e)
        {
            ASPxPageControl pageControl = new ASPxPageControl();
            var dbStdQuery = new StdQuerySQL(StdQuery.QueryName);
            var tpGrid = new TabPage();
            tpGrid.Text = "表格数据";
            tpGrid.Controls.Add(new LiteralControl("<iframe id='iframeGrid' frameborder='0' height='100%' width='100%' scrolling='no' src='GridPage.aspx" + HttpContext.Current.Request.Url.Query + "' scrolling='auto'></iframe>"));
            pageControl.TabPages.Add(tpGrid);


            if ((dbStdQuery.StdQuery.Property & 8) != 8 && dbStdQuery.StdQuery.InCharts != null && dbStdQuery.StdQuery.InCharts.Trim().Length != 0)
            {
                InChart ic = new InChart(dbStdQuery.StdQuery.InCharts);
                int index = 0;
                foreach (var i in ic.SciptObject)
                {
                    var tpChart = new TabPage();
                    tpChart.Text = i.Key;
                    tpChart.Controls.Add(new LiteralControl("<iframe class='iFrameChart' style='width:100%; height:380px;' frameborder='no' framespacing='0' border='0' url='ChartPage.aspx" + HttpContext.Current.Request.Url.Query + "&_Chart=" + index++ + "' src=''></iframe>"));
                    pageControl.TabPages.Add(tpChart);
                }
                //pageControl.ClientSideEvents.TabClick = "TabClick";
                pageControl.ClientSideEvents.TabClick = "function(s,e){if (e.tab.index!=0){" +
                    "var iframe=$(s.mainElement).find(\"tbody > tr:eq(1) > td > div:eq(\"+e.tab.index+\") > iframe\");" +
                    "if (iframe.attr(\"url\")){iframe.attr(\"src\",iframe.attr(\"url\"));iframe.removeAttr(\"url\");}" +
                    "}}";
            }

            pageControl.ClientSideEvents.ActiveTabChanging = "function(s, e) { processOnServer = false;cancel = false;reloadContentOnCallback = false;}";
            pageControl.AutoPostBack = false;
            pageControl.Width = new Unit("100%");
            pageControl.Height = new Unit("100%");
            pageControl.ContentStyle.BorderLeft.BorderStyle = BorderStyle.None;
            pageControl.ContentStyle.BorderRight.BorderStyle = BorderStyle.None;
            pageControl.ContentStyle.BorderBottom.BorderStyle = BorderStyle.None;
            pageControl.ContentStyle.Paddings.Padding = 0;
            form1.Controls.Add(pageControl);
        }
    }
}